package mrusanov.terrain

sealed trait TerrainType {
  def path:String
  def name:String
  def messageKey:String
}

object TerrainType {
  val all = List(Grass, Swamp, Snow, Sand, Hill, Forest, Water, Mountain)

  def parseType(t:String):TerrainType = {
    val foundType = all.find(_.name == t)
    foundType match {
      case Some(ft) => ft
      case None => throw new IllegalArgumentException("Not able to find terrain type with name " + t)
    }
  }

  def createDefenceMap(defence:List[Int]):Map[TerrainType, Int] = {
    require(defence.size == all.size, "Input list size is incorrect!")

    (all zip defence).toMap
  }

  private [this] var map = Map[TerrainType, Set[TerrainType]]()

  map += (Grass -> Set(Sand))
  map += (Swamp -> Set(Water, Snow))
  map += (Snow -> Set(Swamp))
  map += (Sand -> Set(Grass))
  map += (Hill -> Set(Mountain))
  map += (Forest -> Set())
  map += (Water -> Set(Swamp))
  map += (Mountain -> Set(Hill))

  def boundTypes(terrain:TerrainType):Set[TerrainType] = {
    map(terrain)
  }

  def parseTypes(line:String):Set[TerrainType] = {
    line.split(",").map(parseType(_)).toSet
  }
}

object Grass extends TerrainType {
  val path = "data/images/terrain/grass.png"
  val name = "Grass"
  val messageKey = "terrainType.grass"
}

object Swamp extends TerrainType {
  val path = "data/images/terrain/swamp.png"
  val name:String = "Swamp"
  val messageKey = "terrainType.swamp"
}

object Snow extends TerrainType {
  val path = "data/images/terrain/snow.png"
  val name:String = "Snow"
  val messageKey = "terrainType.snow"
}

object Sand extends TerrainType {
  val path = "data/images/terrain/sand.png"
  val name:String = "Sand"
  val messageKey = "terrainType.sand"
}

object Hill extends TerrainType {
  val path = "data/images/terrain/hills.png"
  val name = "Hill"
  val messageKey = "terrainType.hill"
}

object Forest extends TerrainType {
  val path = "data/images/terrain/forest.png"
  val name:String = "Forest"
  val messageKey = "terrainType.forest"
}

object Water extends TerrainType {
  val path = "data/images/terrain/water.png"
  val name:String = "Water"
  val messageKey = "terrainType.water"
}

object Mountain extends TerrainType {
  val path = "data/images/terrain/mountain.png"
  val name:String = "Mountain"
  val messageKey = "terrainType.mountain"
}